package org.jeecg.modules.demo.mes.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.demo.mes.entity.MesWorkOrderDetail;
import org.jeecg.modules.demo.mes.mapper.MesWorkOrderDetailMapper;
import org.jeecg.modules.demo.mes.service.IMesWorkOrderDetailService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 工单详情表
 * @Author: jeecg-boot
 * @Date:   2022-11-02
 * @Version: V1.0
 */
@Service
public class MesWorkOrderDetailServiceImpl extends ServiceImpl<MesWorkOrderDetailMapper, MesWorkOrderDetail> implements IMesWorkOrderDetailService {

    @Override
    public List<MesWorkOrderDetail> queryMesWorkOrderDetailListSelective(Map<String, Object> cxMap) throws JeecgBootException {
        if (cxMap==null){
            return new ArrayList<>();
        }
        return this.baseMapper.queryMesWorkOrderDetailListSelective(cxMap);
    }

    @Override
    public String queryMesWorkOrderIdByWorkOrderBarCode(String workOrderBarCode) throws JeecgBootException {
        if (StringUtils.isBlank(workOrderBarCode)){
            return null;
        }
        final MesWorkOrderDetail workOrderDetail = queryMesWorkOrderDetailByWorkOrderBarCode(workOrderBarCode);
        if (workOrderDetail!=null){
            return workOrderDetail.getWorkOrderId();
        }
        return null;
    }

    @Override
    public MesWorkOrderDetail queryMesWorkOrderDetailByWorkOrderBarCode(String workOrderBarCode) throws JeecgBootException {
        if (StringUtils.isBlank(workOrderBarCode)){
            return null;
        }
        final Map<String,Object> cxMap = new HashMap<>();
        cxMap.put("workOrderBarCode",workOrderBarCode);
        final List<MesWorkOrderDetail> workOrderDetailList = queryMesWorkOrderDetailListSelective(cxMap);
        if (workOrderDetailList!=null && workOrderDetailList.size()==1){
            return workOrderDetailList.get(0);
        }
        return null;
    }

    @Override
    public Integer queryProcedureWorkOrderCount(Map<String, Object> cxMap) throws JeecgBootException {
        if (cxMap==null){
            return 0;
        }
        return this.baseMapper.queryProcedureWorkOrderCount(cxMap);
    }
}
